package com.model.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;

import com.model.service.admin.AdminService;
import com.model.service.student.StudentService;
import com.model.vo.Admin;


@SuppressWarnings("serial")
public class LoginAction extends BaseAction implements SessionAware{

	@SuppressWarnings("rawtypes")
	Map session;
	Admin admin;
  @Autowired
  AdminService adminService;
  @Autowired
  StudentService studentService;
  String resultView;   //视图页面
   /**
    * 登录页面
    */
	@Override
	public String execute() throws Exception {
		
		return INPUT;
	}
	/**
	 * 登录校验
	 * @return
	 */
    @SuppressWarnings({ "unused", "unchecked" })
	private String isLogin() {
    	List<Admin> list = adminService.QueryByHqlList("from admin where admin=? and password=?", new Object[]{admin.getName(),admin.getPassword()});
		if(list.size()>0){
			resultView = "/admin/login.action";
			session.put("name", admin.getName());
		}
    	return SUCCESS;

	}
    /**
     * 登录成功去主页
     * @return
     */
	@SuppressWarnings("unused")
	private String LoginToMain() {
    	resultView = "/admin/main.jsp";
		return SUCCESS;
	}
	/**
	 * 退出登录
	 */
    @SuppressWarnings("unused")
	private String  OutLogin() {
	
    	session.remove("name");
    	resultView = "/admin/login.action";
		return SUCCESS;
    	
	}
	@SuppressWarnings("rawtypes")
	@Override
	public void setSession(Map session) {
		this.session = session;
	}
}
